/**
 * Copyright (c) 2002-2011 旭鸣信息
 * All rights reserved. 
 * File：GoodsService.java
 * History:
 *       May 11, 2012: Initially created, liuzhi.
 */
package com.xteam.ecsystem.service.admin;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xteam.ecsystem.dao.IGoodsDao;
import com.xteam.ecsystem.entities.SysServerConfig;
import com.xteam.ecsystem.utils.GoodsQueryCenterStation;

/**
 * 商品业务处理类
 * 
 * @author liuzhi
 * 
 */
@Service
public class GoodsService {
	
	@Autowired
	private IGoodsDao goodsDao;

	/**
	 * 查找图片
	 * @author liuzhi 2013-12-24
	 * @param bgpId
	 * @return
	 */
	public String findPicture(String bgpId) {
		return this.goodsDao.findPicture(bgpId);
	}

	/**
	 * 新增或者修改商品信息
	 * @author liuzhi
	 * @param obj
	 * @param id
	 * @return
	 */
	public String saveOrUpdateObject(Object obj, String id) {
		return this.goodsDao.saveOrUpdateObject(obj, id);
	}

	/**
	 * 条件查询和分页显示商品信息
	 * @author liuzhi
	 * @param index
	 * @param size
	 * @param goodsStation
	 * @return
	 */
	public String getGoodsList(int pageIndex, int pageSize,
			GoodsQueryCenterStation goodsStation) {
		return this.goodsDao.getGoodsList(pageIndex, pageSize, goodsStation);
	}

	/**
	 * 根据商品编号获得对应的商品信息
	 * @author liuzhi
	 * @param id
	 * @return
	 */
	public String getGoodsInfoById(String id) {
		return this.goodsDao.getGoodsInfoById(id);
	}

	/**
	 * 根据商品编号修改商品状态 0：无效 1：有效
	 * @author liuzhi
	 * @param id
	 */
	public void updateGoodsStateById(String id) {
		this.goodsDao.updateGoodsStateById(id);
	}

	/**
	 * 根据商品编号修改精品商品推荐状态 0：不推荐 1：推荐
	 * @author liuzhi
	 * @param id
	 */
	public void updateBgiBestById(String id) {
		this.goodsDao.updateBgiBestById(id);
	}

	/**
	 * 根据商品编号修改新品商品推荐状态 0：不推荐 1：推荐
	 * @author liuzhi
	 * @param id
	 */
	public void updateBgiNewById(String id) {
		this.goodsDao.updateBgiNewById(id);
	}

	/**
	 * 根据商品编号修改热销商品推荐状态 0：不推荐 1：推荐
	 * @author liuzhi
	 * @param id
	 */
	public void updateBgiHotById(String id) {
		this.goodsDao.updateBgiHotById(id);
	}

	/**
	 * 根据商品编号修改团购商品推荐状态 0：不推荐 1：推荐
	 * @author liuzhi
	 * @param id
	 */
	public void updateBgiBuyById(String id) {
		this.goodsDao.updateBgiBuyById(id);
	}

	/**
	 * 根据传递条件（add/query），加载商品分类treeselect
	 * @author liuzhi
	 * @param type
	 * @return
	 */
	public String getBggTreeSelect(String type) {
		return this.goodsDao.getBggTreeSelect(type);
	}

	/**
	 * 查询面板，加载商品品牌combobox
	 * @author liuzhi
	 * @return
	 */
	public String getBgbCombobox() {
		return this.goodsDao.getBgbCombobox();
	}

	/**
	 * 查询面板，加载供货商combobox
	 * @author liuzhi
	 * @return
	 */
	public String getBgsCombobox() {
		return this.goodsDao.getBgsCombobox();
	}

	/**
	 * 根据商品类型获得类型属性表所有数据
	 * @author liuzhi
	 * @param btaGtype
	 * @return
	 */
	public String getAllGoodsTypeAttr(String btaGtype) {
		return this.goodsDao.getAllGoodsTypeAttr(btaGtype);
	}

	/**
	 * 保存（添加或编辑）商品属性信息
	 * @author liuzhi
	 * @param bgiId
	 * @param btaGtype
	 * @param dynamicArray
	 * @param staticArray
	 */
	public void saveGoodsAttr(String bgiId, String btaGtype,
			JSONArray dynamicArray, JSONArray staticArray) {
		this.goodsDao.saveGoodsAttr(bgiId, btaGtype, dynamicArray, staticArray);
	}

	/**
	 * 根据商品编号获得对应的商品属性信息
	 * @author liuzhi
	 * @param id
	 * @return
	 */
	public String getGoodsAttrByBgiId(String id) {
		return this.goodsDao.getGoodsAttrByBgiId(id);
	}
	
	/**
	 * 根据商品编号从商品属性表中获取商品类型，然后根据商品类型加载指定的类型属性列表，
	 * 以此来创建商品属性表格。
	 * @author liuzhi Jan 15, 2013
	 * @param bgaGoods
	 * @return
	 */
	public String getGoodsAttrTab(String bgaGoods){
		return this.goodsDao.getGoodsAttrTab(bgaGoods);
	}
	
	/**
	 * 根据商品分类获得对应的商品类型
	 * @author liuzhi Jan 15, 2013
	 * @param bgaGgroup
	 * @return
	 */
	public String getBgtByBggId(String bgaGgroup){
		return this.goodsDao.getBgtByBggId(bgaGgroup);
	}

	/**
	 * 删除图片
	 * @author liuzhi 2013-12-24
	 * @param id
	 */
	public void delPicture(String id) {
		goodsDao.delPicture(id);
	}

	/**
	 * 保存图片
	 * @author liuzhi 2013-12-24
	 * @param obj
	 * @param id
	 * @param serverCfg
	 */
	public void saveOrUpdatePicture(Object obj, String id, SysServerConfig serverCfg) {
		goodsDao.saveOrUpdatePicture(obj, id, serverCfg);
	}

	/**
	 * 分页查询商品图片
	 * @author lxj
	 * @param pageIndex
	 * @param pageSize
	 * @param id
	 * @return
	 */
	public String getGoodsPicture(int pageIndex, int pageSize, String id) {
		return this.goodsDao.getGoodsPicture(pageIndex, pageSize, id);
	}

	/**
	 * 条件查询和分页显示商品回收信息
	 * @author liuzhi
	 * @param index
	 * @param size
	 * @param bgiKeyword
	 * @return
	 */
	public String getGoodsTrashList(int pageIndex, int pageSize,
			String bgiKeyword) {
		return this.goodsDao.getGoodsTrashList(pageIndex, pageSize, bgiKeyword);
	}

	/**
	 * 删除单条或多条商品信息
	 * @author liuzhi
	 * @param ids
	 */
	public void delGoods(String ids) {
		this.goodsDao.delGoods(ids);
	}

	/**
	 * 还原单条或多条商品信息
	 * @author liuzhi
	 * @param ids
	 */
	public void saveRevertGoods(String ids) {
		this.goodsDao.saveRevertGoods(ids);
	}

	/**
	 * 添加商品配件
	 * @author ls
	 * @param ids
	 */
	public void saveAccessories(String ids, String bgiId) {
		this.goodsDao.saveAccessories(ids, bgiId);
	}

	/**
	 * 获取商品配件列表
	 * @author ls
	 * @param pageIndex
	 * @param pageSize
	 * @param bgiId
	 * @return
	 */
	public String getAccessoriesList(int pageIndex, int pageSize, String bgiId) {
		return this.goodsDao.getAccessoriesList(pageIndex, pageSize, bgiId);
	}

	/**
	 * 添加商品关联
	 * @author Administrator
	 * @param bgiIds
	 * @param brgIsDoulbes
	 * @param bgiId
	 */
	public void saveAssociation(String brgRgoods, String brgIsDoulbes, String bgiId) {
		this.goodsDao.saveAssociation(brgRgoods, brgIsDoulbes, bgiId);
	}

	/**
	 * 获取商品关联列表
	 * @author ls
	 * @param pageIndex
	 * @param pageSize
	 * @param bgiId
	 * @return
	 */
	public String getAssociationList(int pageIndex, int pageSize, String bgiId) {
		return this.goodsDao.getAssociationList(pageIndex, pageSize, bgiId);
	}

	/**
	 * 添加关联文章
	 * @author ls
	 * @param baiIds
	 * @param bgiId
	 */
	public void saveGoodsAricles(String baiIds, String bgiId) {
		this.goodsDao.saveGoodsAricles(baiIds, bgiId);
	}

	/**
	 * 获取关联文章列表
	 * @author ls
	 * @param pageIndex
	 * @param pageSize
	 * @param bgiId
	 * @return
	 */
	public String getArticlesList(int pageIndex, int pageSize, String bgiId) {
		return this.goodsDao.getArticlesList(pageIndex, pageSize, bgiId);
	}

	/**
	 * 保存上传的图片
	 * @author liuzhi 2013-12-24
	 * @param fileNames
	 * @param bgiId
	 * @param serverCfg
	 */
	public void uploadGoodsPic(String fileNames, String bgiId, SysServerConfig serverCfg) {
		this.goodsDao.uploadGoodsPic(fileNames, bgiId, serverCfg);
	}
	
	/**
	 * 批量更改图片集
	 * @author liuzhi 2013-12-24
	 * @param bgpId
	 * @param bgpDesc
	 * @param bgpState
	 * @param bgpOrder
	 * @param isDeleted
	 */
	public void updatePics(String[] bgpId, String[] bgpDesc,
			String[] bgpState, String[] bgpOrder,String[] isDeleted ) {
		this.goodsDao.updatePics(bgpId,bgpDesc,bgpState,bgpOrder,isDeleted);
	}

	/**
	 * 根据商品分类编号加载商品属性表格数据，进而绘制该表格
	 * @author liuzhi Oct 15, 2013
	 * @param bggId
	 * @return
	 */
	public String getBgaTabData(String bggId) {
		return this.goodsDao.getBgaTabData(bggId);
	}

	/**
	 * 绘制指定商品的属性列表
	 * @author liuzhi Oct 16, 2013
	 * @param bgiId
	 * @param bgiGroup
	 * @return
	 */
	public String getBgaTabPrint(String bgiId, String bgiGroup) {
		return this.goodsDao.getBgaTabPrint(bgiId, bgiGroup);
	}

	/**
	 * 保存商品关联
	 * @author liuzhi Oct 22, 2013
	 * @param brgRgoods
	 * @param brgIsDoulbes
	 * @param bgiId
	 */
	public void saveBrgInfo(String brgRgoods, String brgIsDoulbes, String bgiId) {
		this.goodsDao.saveBrgInfo(brgRgoods, brgIsDoulbes, bgiId);
		
	}

}
